#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <sys/types.h>

void* thr(void* arg) {
    while(1) {
        int a;
        int b;
         pthread_testcancel();   // 设置取消点
        printf("=======\n");
    }
}


int main()
{
    pthread_t tid;
    int ret = pthread_create(&tid, NULL, thr, NULL);
    if(ret != 0) {
        printf("pthrad_create error, %d\n", strerror(ret));
        exit(1);
    }
    printf("主线程 pid = %d, id = %d", getpid(), pthread_self());
    
    sleep(3);
    pthread_cancel(tid);   // 杀死线程
    
    pthread_join(tid, NULL);

    return 0;
}

